package com.zx.deploy.controller;

import com.zx.deploy.common.os.OSinfo;
import com.zx.deploy.common.utils.FileUtil;
import com.zx.deploy.common.utils.ReturnModel;
import com.zx.deploy.config.DeployConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by IBM on 2018/3/30.
 */
@Controller
@RequestMapping("/dbBackup")
public class DbBackupController {

    @Resource
    private DeployConfig deployConfig;

    @GetMapping("/index")
    public String index(){
        return "db_backup";
    }

    /**
     * 数据备份列表展示
     * @return
     */
    @ResponseBody
    @GetMapping("/list")
    public Object list(){
        try {
        	String ext="gz";
        	if (OSinfo.isWindows()) ext="sql";
        		
            return ReturnModel.success("成功",FileUtil.listFiles(deployConfig.backups_database_path,ext));
        } catch (Exception e) {
            e.printStackTrace();
            return ReturnModel.error("查询数据备份列表失败");
        }
    }
}
